<!-- 使用 type="home" 属性设置首页，其他页面不需要设置，默认为page；推荐使用json5，更强大，且允许注释 -->
<route lang="json5">
{
  style: {
    navigationStyle: 'custom',
    navigationBarTitleText: '可领取优惠卷',
  },
  navigationBarRightButton: {
    hide: true,
  },
}
</route>
<template>
  <view
    class="w-full h-full bg-white overflow-hidden box-border"
    :style="{ paddingTop: safeAreaInsets?.top + 'px' }"
  >
    <view class="w-full h-full home-container">
      <wd-navbar @click-left="handleClickLeft">
        <template #title>
          <text class="text-gray-333 font-size-36 font-500">可领取优惠卷</text>
        </template>
        <template #left>
          <wd-icon
            name="chevron-left"
            class="text-gray-333 font-size-44"
            @click="pagesBack"
          ></wd-icon>
        </template>
      </wd-navbar>
      <view class="w-full h-full home-content">
        <view class="w-full hr-300">
          <image width="100%" height="100%" :src="'../../static/images/background/coupon.png'" />
        </view>
        <view class="w-full p-y-32 pos-relative pos-top--60 bg-#fff">
          <view
            class="w-full hr-236 pos-relative z-1 mg-t-32"
            v-for="(item, index) in dataList"
            :key="index"
          >
            <view class="pos-absolute pos-top-0 pos-left-0 w-full h-full z-0">
              <image
                width="100%"
                height="100%"
                :src="'../../static/images/background/coupon-bg.png'"
              />
            </view>
            <view class="pos-relative z-1 p-x-28 p-y-28">
              <view class="flex justify-between items-center">
                <view class="flex justify-start items-end text-blue-1 font-600 line-height-none">
                  <view class="font-size-28 mg-b-6 mg-r-6">¥</view>
                  <view class="font-size-64">{{ item.min_buy_amount }}</view>
                </view>
                <view class="hr-70">
                  <wd-button type="primary" size="small" @click="getCouponsItem(item)">
                    <text class="font-size-32 text-white font-500 ps-l-10 ps-r-10">领取优惠卷</text>
                  </wd-button>
                </view>
              </view>
              <view class="mg-t-6 p-x-5">
                <text class="font-size-28 text-gray-333 font-500">{{ item.type }}</text>
              </view>
              <view class="mg-t-26">
                <text class="font-size-24 text-gray-999 font-400">
                  使用期限：{{ item.expire_at }}
                </text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { couponReceive, getCoupons } from '@/service/shop/shop'

defineOptions({
  name: 'Coupon',
})
const { safeAreaInsets } = uni.getSystemInfoSync()
const handleClickLeft = () => {}
const pagesBack = () => {
  uni.navigateBack()
}
onLoad(() => {})
onShow(() => {
  getData()
})
const dataList: any = ref([])
const getData = () => {
  getCoupons().then((res: any) => {
    if (res.data) {
      dataList.value = res.data
    }
  })
}
const getCouponsItem = (item: any) => {
  couponReceive({ id: item.id }).then((res: any) => {
    uni.showToast({
      title: '领取成功',
      icon: 'none',
      duration: 1000,
    })
    getData()
  })
}
</script>

<style scoped lang="scss">
.home-container {
  position: relative;
  z-index: 1;
}
.home-content {
  height: calc(100% - var(--wot-navbar-height, 88rpx));
  overflow: auto;
}
.tab-con-height {
  height: calc(100vh - 256rpx);
}
.coupon-use {
  filter: grayscale(100%);
}
::v-deep .wd-button {
  width: 100% !important;
  height: 100% !important;
}
::v-deep .wd-tabs__nav-item {
  height: 58rpx !important;
  font-size: 32rpx !important;
  line-height: 38rpx !important;
  color: #312f2a !important;
}
::v-deep .wd-tabs__nav {
  height: 58rpx !important;
}
</style>
